/*************************************************************
 * Title: Pagination.java
 * Description: 
 * Author: Huang Shaobin
 * Email: shaobin.software@gmail.com
 * CreateTime: Feb 21, 2013 3:33:56 PM
 ************************************************************/
package snow.core.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

import org.apache.commons.lang.ArrayUtils;

/**
 *
 */
@SuppressWarnings("serial")
public class Pagination implements Serializable {

	private Object[] records;
	private Long totalCounts;

	public Pagination(Object[] records, Long totalCounts) {
		this.records = records == null ? ArrayUtils.EMPTY_OBJECT_ARRAY : records;
		this.totalCounts = totalCounts == null || totalCounts.longValue() < records.length ? Long.valueOf(records.length) : totalCounts;
	}

	public Pagination(Collection<?> records, Long totalCounts) {
		this((records == null ? Collections.emptyList() : records).toArray(), totalCounts);
	}

	public Object[] getRecords() {
		final Object[] records = new Object[this.records.length];
		System.arraycopy(this.records, 0, records, 0, this.records.length);
		return records;
	}

	public Long getTotalCounts() {
		return totalCounts;
	}

	public void setRecords(Object[] records) {
	}

	public void setTotalCounts(Long totalCounts) {
	}

}
